package com.xjh.controller;

import com.ejlchina.searcher.MapSearcher;
import com.ejlchina.searcher.SearchResult;
import com.ejlchina.searcher.util.MapUtils;
import com.xjh.basestudy.designmode.behaviorMode.behaviorMode7_Mediator.p2_mediator.User;
import com.xjh.bo.BeanSearchStudentBO;
import com.xjh.service.AclUserService;
import com.xjh.utils.resultutils.ResponseObj;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Author:XuJianHua
 * Date:2022/10/13
 * Description:
 */
@RestController
@RequestMapping("/api/searchBean")
@Slf4j
public class TestSearchBeanController {
    @Autowired
    private MapSearcher mapSearcher;  // 注入检索器（由 bean-searcher-boot-starter 提供）

    @Autowired
    private AclUserService userService;

    /**
     * @Author: XuJianHua
     * @Date 2022/10/13 15:26
     * @Description: 使用mapSercher进行查询
     **/
    @GetMapping("/index")
    public SearchResult<Map<String, Object>> index(HttpServletRequest request) {
        // 这里咱们只写一行代码
        return mapSearcher.search(BeanSearchStudentBO.class, MapUtils.flat(request.getParameterMap()));
    }

    /**
     * @Author: XuJianHua
     * @Date 2022/10/13 15:24
     * @Description: 测试从service层构造sql查询，使用beanSercher进行查询
     **/
    @GetMapping("/index1")
    public ResponseObj testBeanSearcher() {
        ResponseObj responseObj = new ResponseObj();
        List<BeanSearchStudentBO> list = userService.testBeanSearcher();
        return responseObj.ok(list);
    }
}
